﻿function JobMgmt() {
    this.VesselCode = null;
    this.SystemCode = null;
    this.JobID = null;
    this.JobCode = null;
    this.JobTitle = null;
    this.JobDescription = null;
    this.Periodicity = null;
    this.PeriodicityType = null;
    this.Priority = null;
    this.AllMeasurements = null;
    this.SelectedMeasurements = null;
    this.JobType = null;


    this.PerformSave = function () {
        var currentBusinessObject = null;

        if (this.JobID.value.trim() == '') {
            currentBusinessObject = new Landscape.Job();
            currentBusinessObject.CreatedBy = GetCurrentUserCode();
            currentBusinessObject.CreatedDate = new Date();
            currentBusinessObject.ID = '00000000-0000-0000-0000-000000000000';
        }
        else {
            currentBusinessObject = new Landscape.Job();
            currentBusinessObject.ID = this.JobID.value.trim();
        }

        currentBusinessObject.UpdatedBy = GetCurrentUserCode();
        currentBusinessObject.UpdatedDate = new Date();
        currentBusinessObject.Code = this.JobCode.get_value().trim();
        currentBusinessObject.Title = this.JobTitle.get_value().trim();
        currentBusinessObject.Description = this.JobDescription.get_html(true);
        currentBusinessObject.Periodicity = this.Periodicity.get_value();
        currentBusinessObject.PeriodicityUnit = this.PeriodicityType.get_text();
        currentBusinessObject.Priority = this.Priority.get_value();
        currentBusinessObject.JobType = 'PLANNED';
        currentBusinessObject.JobVersion = 1;
        currentBusinessObject.Measurements = new Array();
        for (var idx = 0; idx < this.SelectedMeasurements.get_items().get_count(); idx++) {
            currentBusinessObject.Measurements.push(this.SelectedMeasurements.get_items().getItem(idx).get_text());
        }

        currentBusinessObject.IsDeleted = false;
        currentBusinessObject.IsReleased = false;
        currentBusinessObject.VesselItemID = this.SystemCode.value.trim();

        Landscape.MaintenanceActions.SaveJob(currentBusinessObject, function (result, e) {
            N_NotifyMessage('Job Details !!!', 'Job details saved successfully...', 1);
        }, function (result, e) {
            N_NotifyMessage('Error !!!', result.get_message(), 2);
        });
    }

    this.ListJobs = function () {

    }

    this.PerformLoad = function () {

        Landscape.MaintenanceActions.GetJobByID(this.JobID.value.trim(), function (result, e) {
            this.JobTitle.set_value(result.Title);
            this.JobCode.set_value(result.Code);
            this.JobDescription.set_html(result.Description);
            this.Periodicity.set_value(result.Periodicity);
            this.Priority.set_value(result.Priority);

        }, function (result, e) { });
    }

}